package org.deng.learn.designpattern.observer;

import java.util.HashSet;
import java.util.Set;

/**
 * @author DengLibin
 * @Description
 * 被观察者，也就是微信公众号服务
 * @Date 2019/2/15 0015 14:31
 */

public class WechatServer implements Observerable {
    private Set<Observer> set;

    public  WechatServer(){
        set = new HashSet<>();
    }
    @Override
    public synchronized void registerObserver(Observer observer) {
        set.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        set.remove(observer);
    }

    @Override
    public void notifyObserver(String msg) {
        for(Observer observer : set){
            observer.update(msg);
        }
    }

    public  void sendMsg(String s){
        notifyObserver(s);
    }
}
